package com.flame.shapeville.controller.task;

/**
 * Abstract controller for tasks that support detailed view of shapes or solutions.
 * Extends JfTaskController with additional methods for showing detailed explanations.
 *
 * @author Flame Dev Team
 * @version 1.0
 * @since 2025-05-15
 */
public abstract class JfTaskDetailedController extends JfTaskController {

    /**
     * Overrides default behavior to show detailed view on wrong answer when chances are exhausted.
     *
     * @param answer the user's submitted answer
     */
    @Override
    void answerAnimationAndSave(String answer) {
        boolean result = curExercise.answer(answer, time);
        if (result) {
            Integer misCount = curExercise.getMisCount();
            if (misCount == 0) {
                notice.setText("Excellent!!!");
            } else if (misCount == 1) {
                notice.setText("Perfect!");
            } else {
                notice.setText("Good job");
            }
            notice.setStyle("-fx-fill: orange");
            finishClock();
        } else {
            if (curExercise.getChance() == 0) {
                notice.setText("Sorry, you have no chance");
                finishClock();
                showDetailed();
            } else {
                notice.setText("Wrong answer");
            }
            notice.setStyle("-fx-fill: red");
        }
        noticeFt.play();
        exerciseService.saveExercise(curExercise);
        flushInput();
    }

    /**
     * Overrides timeout to show detailed explanation.
     */
    @Override
    void timeoutAnimationAndSave() {
        super.timeoutAnimationAndSave();
        showDetailed();
    }

    /**
     * Abstract method to show detailed explanation or solution.
     */
    abstract void showDetailed();
}
